Page({
  data: {
    false_questions:[],
    current_index: 0,
    lastPage: 0,
    current_page:null,
    buttonText:'查看下一错题',
    true_answer:'',
    false_answer:''
  },

  onLoad: function (options) {
   
    try {
      let questions = wx.getStorageSync('false_questions');
      let self = this;
      let value = questions[self.data.current_index];
      let len = questions.length;
      let fAnswer = questions[self.data.current_index].options[questions[self.data.current_index].userchoose]
  
      for (let item in questions[self.data.current_index].options){
        if (questions[self.data.current_index].options[item].key =='true'){
          self.setData({
            true_answer: questions[self.data.current_index].options[item]
          })
        }
      }


      if(questions){
        self.setData({
          false_questions:questions,
          current_page:value,
          lastPage:len,
          false_answer:fAnswer
        })
      }

      if (this.data.current_index + 2 >= this.data.lastPage) {
        this.setData({
          buttonText: '重新测试'
        })
      }

    } catch (e) {
      console.log(e.message);
    }
    console.log(this.data.true_answer);
    console.log(this.data.current_page);
  },


  onReady: function () {
  },

  next: function(){
    if (this.data.current_index + 1 >= this.data.lastPage){
      wx.navigateBack({
        url: '../index/index'
      })
    }else{
      //点击加载下一道错题的内容
      if (this.data.current_index + 2 >= this.data.lastPage) {
        this.setData({
          buttonText: '重新测试'
        })
      }
     
     let index = this.data.current_index + 1;
      var contentText = this.data.false_questions[index]

      for (let item in contentText.options) {
        if (contentText.options[item].key == 'true') {
          this.setData({
            true_answer: contentText.options[item]
          })
        }
      }
      let fanswer = contentText.options[contentText.userchoose];

      this.setData({
        current_index:index,
        current_page: contentText,
        false_answer:fanswer
      })
    }
  }



})